package com.ymatou.iapi.sellercs.testcase;

import java.io.IOException;

import org.apache.http.client.ClientProtocolException;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.google.gson.JsonObject;
import com.ymatou.iapi.sellercs.parameter.GetSellerMessageUnreadCountBean;
import com.ymatou.iapi.sellercs.parameter.SendMessageBean;
import com.ymatou.iapi.sellercs.service.GetSellerMessageUnreadCountCall;
import com.ymatou.iapi.userregister.parameter.UserRegisterInfoRequestDtoBean;
import com.ymatou.iapi.userregister.service.UserRegisterInfoRequestDtoCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.JUserCallService;
import com.ymttest.business.service.SellerCSIMCallService;
import com.ymttest.database.sqlwapper.YmtSellerCSIMWapper;
import com.ymttest.utils.EnvSetup;
/**
*获取私信列表
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_GetSellerMessageUnreadCount{
	private static GetSellerMessageUnreadCountBean getsellermessageunreadcountBean;
	private static GetSellerMessageUnreadCountCall getsellermessageunreadcountCall;
	private static int sellerId = Integer.parseInt(EnvSetup.getData("autotest_seller1"));
	private static String sellername = EnvSetup.getData("autotest_sellerName1");
	private static int zsellerId = Integer.parseInt(EnvSetup.getData("autotest_seller_z"));
	private static YmtSellerCSIMWapper YmtSellerCSIMWapper;
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("获取私信列表");
	}

	@Before
	public void caseUp() throws ClientProtocolException, IOException {
		getsellermessageunreadcountBean=new GetSellerMessageUnreadCountBean();
		getsellermessageunreadcountCall=new GetSellerMessageUnreadCountCall();
		YmtSellerCSIMWapper=new YmtSellerCSIMWapper();
		SellerCSIMCallService.OffLine(sellerId, null);
		SellerCSIMCallService.OffLine(zsellerId, null);
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getsellermessageunreadcountCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetSellerMessageUnreadCount_001() {
		Logger.start(true,"获取买手是否有未读消息成功,有");
		try {
			Logger.comment("注册新用户");
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);

			JsonObject registerResult = urrc.getJsonObject().get("Result").getAsJsonObject();
			String token = registerResult.get("Token").getAsString();
			Integer userId = urrc.getUserid();
			Logger.comment("删除旧数据");
			YmtSellerCSIMWapper.deleteYmtOnlinecsByCsid(sellerId);
			//APP上线
			SellerCSIMCallService.AppLogin(sellerId);
			SendMessageBean sendmessageBean = SellerCSIMCallService.initSendmessageBean(userId, sellerId, "connect");
			SellerCSIMCallService.SendMessage(sendmessageBean);
			//触发分配
			SellerCSIMCallService.Assign();
			Thread.sleep(3000);
			Logger.debug("getUnReadNum:"+SellerCSIMCallService.getUnReadNum(sellerId));
			getsellermessageunreadcountBean.setSellerId(sellerId);
			getsellermessageunreadcountCall.setData(getsellermessageunreadcountBean);
			getsellermessageunreadcountCall.callService();			
			Logger.verifyEquals("200", getsellermessageunreadcountCall.getString("Status"), "验证Status");
			Logger.verifyEquals(true, getsellermessageunreadcountCall.getJsonObject().get("Result").getAsJsonObject().get("HasUnreadCount").getAsBoolean(), "验证Status");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P3.class})
	@TestCase
	public void Tc_GetSellerMessageUnreadCount_002() {
		Logger.start(true,"不输入sellerid没有查到未读记录");
		try {
			getsellermessageunreadcountCall.setData(getsellermessageunreadcountBean);
			getsellermessageunreadcountCall.callService();			
			Logger.verifyEquals("200", getsellermessageunreadcountCall.getString("Status"), "验证Status");
			Logger.verifyEquals(false, getsellermessageunreadcountCall.getJsonObject().get("Result").getAsJsonObject().get("HasUnreadCount").getAsBoolean(), "验证Status");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_GetSellerMessageUnreadCount_003() {
		Logger.start(true,"获取买手是否有未读消息成功,无");
		try {
			Logger.comment("注册新用户");
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);

			JsonObject registerResult = urrc.getJsonObject().get("Result").getAsJsonObject();
			String token = registerResult.get("Token").getAsString();
			Integer userId = urrc.getUserid();
			Logger.comment("删除旧数据");
			YmtSellerCSIMWapper.deleteYmtOnlinecsByCsid(zsellerId);
			//APP上线
			SellerCSIMCallService.AppLogin(zsellerId);
			SendMessageBean sendmessageBean = SellerCSIMCallService.initSendmessageBean(userId, zsellerId, "connect");
			SellerCSIMCallService.SendMessage(sendmessageBean);
			//触发分配
			SellerCSIMCallService.Assign();
			Thread.sleep(2000);
			Logger.debug("getUnReadNum:"+SellerCSIMCallService.getUnReadNum(zsellerId));
			SellerCSIMCallService.setNoUnRead(zsellerId);
			Thread.sleep(2000);
			getsellermessageunreadcountBean.setSellerId(zsellerId);
			getsellermessageunreadcountCall.setData(getsellermessageunreadcountBean);
			getsellermessageunreadcountCall.callService();			
			Logger.verifyEquals("200", getsellermessageunreadcountCall.getString("Status"), "验证Status");
			Logger.verifyEquals(false, getsellermessageunreadcountCall.getJsonObject().get("Result").getAsJsonObject().get("HasUnreadCount").getAsBoolean(), "验证Status");

			Logger.debug("getUnReadNum:"+SellerCSIMCallService.getUnReadNum(zsellerId));
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_GetSellerMessageUnreadCount_004() {
		Logger.start(true,"获取子账号买手是否有未读消息成功,有");
		try {
			Logger.comment("注册新用户");
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);

			JsonObject registerResult = urrc.getJsonObject().get("Result").getAsJsonObject();
			String token = registerResult.get("Token").getAsString();
			Integer userId = urrc.getUserid();
			Logger.comment("删除旧数据");
			YmtSellerCSIMWapper.deleteYmtOnlinecsByCsid(zsellerId);
			//APP上线
			SellerCSIMCallService.AppLogin(zsellerId);
			SendMessageBean sendmessageBean = SellerCSIMCallService.initSendmessageBean(userId, sellerId, "connect");
			SellerCSIMCallService.SendMessage(sendmessageBean);
			//触发分配
			SellerCSIMCallService.Assign();
			Thread.sleep(3000);
			Logger.debug("getUnReadNum:"+SellerCSIMCallService.getUnReadNum(zsellerId));
			getsellermessageunreadcountBean.setSellerId(zsellerId);
			getsellermessageunreadcountCall.setData(getsellermessageunreadcountBean);
			getsellermessageunreadcountCall.callService();			
			Logger.verifyEquals("200", getsellermessageunreadcountCall.getString("Status"), "验证Status");
			Logger.verifyEquals(true, getsellermessageunreadcountCall.getJsonObject().get("Result").getAsJsonObject().get("HasUnreadCount").getAsBoolean(), "验证Status");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}